SilentAuthMiddleware.handle   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
c 0
b 0
f 0
rs 10
cc 1
1
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
2
3
/**
4
 * Silent auth middleware can be used as a global middleware to silent check
5
 * if the user is logged-in or not.
6
 *
7
 * The request continues as usual, even when the user is not logged-in.
8
 */
9
export default class SilentAuthMiddleware {
10
  /**
11
   * Handle request
12
   */
13
  public async handle({ auth }: HttpContextContract, next: () => Promise<void>) {
14
    /**
15
     * Check if user is logged-in or not. If yes, then `ctx.auth.user` will be
16
     * set to the instance of the currently logged in user.
17
     */
18
    await auth.check()
19
    await next()
20
  }
21
}
22